import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';

import { StringNullableChain } from 'lodash';

import { BaseHttpService } from '../base-http.service';
import { Role } from '../system/role.service';

export interface Maintenance {
  id: number;
  name: string;
  cronStartTime: string;
  cronStopTime: string;
  cronTime: string;
  afterTime: string;
  loopTimes: number;
  cronDetail: {
    cronHours: number[];
    cronMinutes: number[];
    cronMonth: number[];
    cronDays: number;
    cronMonthDay: number[];
    cronWeek: number[];
  };
  comment: string;
  perunit: string;
}

@Injectable({
  providedIn: 'root'
})
export class MantenanceService {
  constructor(public http: BaseHttpService) {}
  public maintenanceGet(id: number): Observable<Maintenance> {
    return this.http.get(`/api/v1/maintenance/${id}/`);
  }

  public maintenanceAdd(param: Maintenance): Observable<void> {
    return this.http.post('/api/v1/maintenance/', param);
  }

  public maintenanceDelete(ids: number[]): Observable<void> {
    return this.http.delete('/api/v1/maintenance', { ids });
  }

  public maintenanceList(param: Role): Observable<void> {
    return this.http.get('/api/v1/maintenance/', param);
  }

  public maintenanceUpdate(id: number, param: Maintenance): Observable<string[]> {
    return this.http.put(`/maintenance/${id}/`, param);
  }
}
